/*
*  Copyright 2019-2020 dhm
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.admin.qujiang.controller;

import me.zhengjie.annotation.Log;
import com.admin.qujiang.model.YlDatakbHallInformationModel;
import com.admin.qujiang.service.IYlDatakbHallInformationService;
import com.admin.qujiang.service.dto.YlDatakbHallInformationQueryCriteria;
import com.admin.qujiang.dto.YlDatakbHallInformationDto;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
* @website https://el-admin.vip
* @author dhm
* @date 2022-05-31
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "大厅信息管理")
@RequestMapping("/api/ylDatakbHallInformation")
public class YlDatakbHallInformationController {

private final IYlDatakbHallInformationService ylDatakbHallInformationService;

@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('ylDatakbHallInformation:list')")
public void download(HttpServletResponse response, YlDatakbHallInformationQueryCriteria criteria) throws IOException {
ylDatakbHallInformationService.download(ylDatakbHallInformationService.queryAll(criteria, false), response);
}

@GetMapping
@Log("查询大厅信息")
@ApiOperation("查询大厅信息")
@PreAuthorize("@el.check('ylDatakbHallInformation:list')")
public ResponseEntity<Object> query(YlDatakbHallInformationQueryCriteria criteria, Boolean isQuery){
    Map<String,Object> result = new HashMap<>();
    List<YlDatakbHallInformationDto> ylDatakbHallInformationDtos = ylDatakbHallInformationService.queryAll(criteria, isQuery);
        result.put("content", ylDatakbHallInformationDtos);
        result.put("totalElements", Optional.ofNullable(ylDatakbHallInformationDtos).orElse(new ArrayList<>()).size());
        return new ResponseEntity<>(result, HttpStatus.OK);
        }

        @PostMapping
        @Log("新增大厅信息")
        @ApiOperation("新增大厅信息")
        @PreAuthorize("@el.check('ylDatakbHallInformation:add')")
        public ResponseEntity<Object> create(@Validated @RequestBody YlDatakbHallInformationModel resources){
            return new ResponseEntity<>(ylDatakbHallInformationService.create(resources),HttpStatus.CREATED);
            }

            @PutMapping
            @Log("修改大厅信息")
            @ApiOperation("修改大厅信息")
            @PreAuthorize("@el.check('ylDatakbHallInformation:edit')")
            public ResponseEntity<Object> update(@Validated @RequestBody YlDatakbHallInformationModel resources){
                ylDatakbHallInformationService.update(resources);
                return new ResponseEntity<>(HttpStatus.NO_CONTENT);
                }

                @Log("删除大厅信息")
                @ApiOperation("删除大厅信息")
                @PreAuthorize("@el.check('ylDatakbHallInformation:del')")
                @DeleteMapping
                public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
                    ylDatakbHallInformationService.deleteAll(ids);
                    return new ResponseEntity<>(HttpStatus.OK);
                    }
                    }